package com.github.common.util.io;

import lombok.extern.slf4j.Slf4j;

import java.io.Closeable;

/**
 * 流工具类
 *
 */
@Slf4j
public class StreamUtil {

    private static final int BUFFER_START_POSITION = 0;

    private static final int CHAR_BUFFER_LENGTH = 1024;

    /**
     * 通用的关闭方法
     */
    public static void close(final AutoCloseable... autoCloseables) {
        if (autoCloseables == null) {
            return;
        }
        for (AutoCloseable closeable : autoCloseables) {
            try {
                if (closeable != null) {
                    closeable.close();
                }
            } catch (Throwable e) {
                log.error("fail to close.", e);
            }
        }
    }

    /**
     * 通用的关闭方法
     */
    public static void close(final Closeable... closeables) {
        closeQuietly(closeables);
    }

    /**
     * 通用的关闭方法
     */
    public static void closeQuietly(final Closeable... closeables) {
        for (Closeable closeable : closeables) {
            try {
                if (null != closeable) {
                    closeable.close();
                }
            } catch (Throwable e) {
                log.error("fail to close.", e);
            }
        }
    }

}
